(function($){
	// Default values
	$.mbScrollingMenuDefault = {
		overflow: 	'hidden',
		padding:	15
	};
			
	// Vertical scrolling menu
	$.fn.mbScrollingMenuVertical = function(p_options) {
		var _options;
		_options = $.extend({}, $.mbScrollingMenuDefault, p_options);
		return this.each(function() {
			var $this = $(this);
			var _o;
			_o = ( $.meta ? $.extend({}, _options, $this.data()) : _options);
			
			//Remove scrollbars	
			$this.css({
				overflow:	'auto',
				overflowX: 	'hidden',
				overflowY: 	_o.overflow 
			});
		
			//When user move mouse over menu
			$this.mousemove(function(e){
			var ulPadding = _o.padding;
				
				//Get menu height
				var divHeight = $this.height();
					
				// add padding
				var ul = $this.find('ul');
				ul.css({
					paddingTop: 	ulPadding,
					paddingBottom:	ulPadding
				});
					
				//Find last list container
				var lastLi = $this.find('li:last-child');
				
				var ulHeight = lastLi[0].offsetTop + lastLi.outerHeight() + ulPadding;	
				var top = (e.pageY - $this.offset().top) * (ulHeight-divHeight) / divHeight;
				$this.scrollTop(top);
			});
		});
	};
	
	// Horizontal scrolling Menu
	$.fn.mbScrollingMenuHorizontal = function(p_options) {
		var _options;
		_options = $.extend({}, $.mbScrollingMenuDefault, p_options);
		return this.each(function() {
		    var $this = $(this);
		    var _o;
			_o = ( $.meta ? $.extend({}, _options, $this.data()) : _options);

				
			//Remove scrollbars	
			$this.css({
				overflow:	'auto',
				overflowX: 	_o.overflow,
				overflowY: 	'hidden'
			});
			
			$this.find('li').css({
				display:	'inline'
			});
		
			var ulPadding = _o.padding;
					
			//Get menu height
			var divWidth = $this.width();
								
			// add padding
			var ul = $this.find('ul');
			ul.css({
				paddingLeft: 	ulPadding,
				paddingRight:	ulPadding
			});
						
			//Find last list container
			var lastLi = ul.find('li:last-child');
					
			//When user move mouse over menu
			$this.mousemove(function(e){		
				var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
				var left = (e.pageX - $this.offset().left) * (ulWidth-divWidth) / divWidth;
				$this.scrollLeft(left);
			});
		});
	};
})(jQuery);